mssql

推荐列表 站点导航

当前位置:首页 > 数据库 > mssql >

获取MSSQL 表结构中字段的备注、主键等信息的sql

来源:网络整理  作者:网络  发布时间:2020-12-09 01:36
本文为大家详细介绍下如何获取MSSQL 表结构中字段的备注、主键等信息,感兴趣的朋友可以参考下...
sysproperties f
长度 = COLUMNPROPERTY(a.id,a.name,'PRECISION'),
where
sys.columns a
systypes b
标识 = case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end,
[主键]=case when exists(select 1 from sys.objects where parent_object_id=a.object_id and type=N'PK' and name in
a.id=g.id and a.colid=g.smallid
on

[类型]=b.Name,
sys.objects c on a.object_id=c.object_id and c.Type='U'
[小数]=isnull(ColumnProperty(a.object_id,a.Name,'Scale'),0),
--2005实现字段属性统计(2000里的系统表sysproperties描述表、字段不存在,2005里用sys.extended_properties视图替代)
[标识]=case when is_identity=1 then '√' else '' end,
字段序号 = a.colorder,
[字节数]=case when a.[max_length]=-1 and b.Name!='xml' then 'max/2G'
on
select
主键 = case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (

获取MSSQL 表结构中字段的备注、主键等信息的sql

left join
[列说明]=isnull(e.[value],''),
inner join
字段说明 = isnull(g.[value],'')
sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.Column_id and e.class=1
[表名]=c.Name,
FROM
sys.types b on a.user_type_id=b.user_type_id
小数位数 = isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
left join
left join
默认值 = isnull(e.text,''),
a.cdefault=e.id
left join
字段名 = a.name,
left join
on
sys.extended_properties f on f.major_id=c.object_id and f.minor_id=0 and f.class=1


sysobjects d
[是否為空]=case when a.is_nullable=1 then '√' else '' end,
left join
2、MSSQL2005

inner join
syscomments d on a.default_object_id=d.ID

from
[长度]=ColumnProperty(a.object_id,a.Name,'Precision'),
else rtrim(a.[max_length]) end,
then '√' else '' end,
[列名]=a.Name,
when b.Name='xml' then ' 2^31-1字节/2G'
[/code]
left join
go
use test--数据库
(select indid from sysindexkeys where and colid=a.column_id)))
(select Name from sys.indexes where index_id in
[表说明]=isnull(f.[value],''),
SELECT
syscolumns a
SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then '√' else '' end,
SELECT name FROM sysindexes WHERE indid in(
类型 = b.name,
a.id,a.colorder
order by
a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
sysproperties g
[默认值]=isnull(d.text,'')
left join
d.name='FI_dept' --如果只查询指定表,加上此条件
结果:
占用字节数 = a.length,
on
syscomments e
[列序号]=a.Column_id,
表名 = case when a.colorder=1 then d.name else '' end,
d.id=f.id and f.smallid=0
表说明 = case when a.colorder=1 then isnull(f.value,'') else '' end,

复制代码 代码如下:


a.xusertype=b.xusertype
允许空 = case when a.isnullable=1 then '√'else '' end,
on

相关热词: MSSQL

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/sql/mssql/1621.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

获取MSSQL 表结构中字段的备注、主键等信息的sql

2020-12-09 编辑:网络

sysproperties f
长度 = COLUMNPROPERTY(a.id,a.name,'PRECISION'),
where
sys.columns a
systypes b
标识 = case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end,
[主键]=case when exists(select 1 from sys.objects where parent_object_id=a.object_id and type=N'PK' and name in
a.id=g.id and a.colid=g.smallid
on

[类型]=b.Name,
sys.objects c on a.object_id=c.object_id and c.Type='U'
[小数]=isnull(ColumnProperty(a.object_id,a.Name,'Scale'),0),
--2005实现字段属性统计(2000里的系统表sysproperties描述表、字段不存在,2005里用sys.extended_properties视图替代)
[标识]=case when is_identity=1 then '√' else '' end,
字段序号 = a.colorder,
[字节数]=case when a.[max_length]=-1 and b.Name!='xml' then 'max/2G'
on
select
主键 = case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (

获取MSSQL 表结构中字段的备注、主键等信息的sql

left join
[列说明]=isnull(e.[value],''),
inner join
字段说明 = isnull(g.[value],'')
sys.extended_properties e on e.major_id=c.object_id and e.minor_id=a.Column_id and e.class=1
[表名]=c.Name,
FROM
sys.types b on a.user_type_id=b.user_type_id
小数位数 = isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
left join
left join
默认值 = isnull(e.text,''),
a.cdefault=e.id
left join
字段名 = a.name,
left join
on
sys.extended_properties f on f.major_id=c.object_id and f.minor_id=0 and f.class=1


sysobjects d
[是否為空]=case when a.is_nullable=1 then '√' else '' end,
left join
2、MSSQL2005

inner join
syscomments d on a.default_object_id=d.ID

from
[长度]=ColumnProperty(a.object_id,a.Name,'Precision'),
else rtrim(a.[max_length]) end,
then '√' else '' end,
[列名]=a.Name,
when b.Name='xml' then ' 2^31-1字节/2G'
[/code]
left join
go
use test--数据库
(select indid from sysindexkeys where and colid=a.column_id)))
(select Name from sys.indexes where index_id in
[表说明]=isnull(f.[value],''),
SELECT
syscolumns a
SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then '√' else '' end,
SELECT name FROM sysindexes WHERE indid in(
类型 = b.name,
a.id,a.colorder
order by
a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
sysproperties g
[默认值]=isnull(d.text,'')
left join
d.name='FI_dept' --如果只查询指定表,加上此条件
结果:
占用字节数 = a.length,
on
syscomments e
[列序号]=a.Column_id,
表名 = case when a.colorder=1 then d.name else '' end,
d.id=f.id and f.smallid=0
表说明 = case when a.colorder=1 then isnull(f.value,'') else '' end,

复制代码 代码如下:


a.xusertype=b.xusertype
允许空 = case when a.isnullable=1 then '√'else '' end,
on

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/sql/mssql/1621.shtml

相关文章

风云图片

推荐阅读

返回mssql频道首页